package com.aaa.service.sas.impl;

import cn.hutool.core.util.ObjectUtil;


import com.aaa.dao.ReturnRecordsDao;
import com.aaa.entity.ReturnRecords;
import com.aaa.entity.sas.TestResultSasTotal;

import com.aaa.entity.sas.TestResultSas;
import com.aaa.dao.sas.TestResultSasDao;
import com.aaa.entity.system.PageOrder;
import com.aaa.service.sas.TestResultSasService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * (TestResultSas)表服务实现类
 *
 * @author makejava
 * @since 2022-09-02 20:05:15
 */
@Service("testResultSasService")
public class TestResultSasServiceImpl implements TestResultSasService {
    @Autowired
    private TestResultSasDao testResultSasDao;

    @Autowired
    private ReturnRecordsDao returnRecordsDao;

    @Override
    public Page queryAllTestResult(PageOrder pageOrder, TestResultSas testResultSas) {
        //拿出pageOrder里面的所有数据
        PageHelper.startPage(pageOrder.getPage(), pageOrder.getLimit());
        //判断数据是否为空
        if (ObjectUtil.isNotEmpty(pageOrder.getField())) {
            PageHelper.orderBy(pageOrder.getFieldOrder());
        }
        ;
        //将实体类型转化为Page类
        List<TestResultSas> list = testResultSasDao.queryAllTestResult(testResultSas);

        Page pageResult = (Page) list;
        return pageResult;
    }


    /**
     * 删除
     *
     * @param id 主键
     * @return
     */
    @Override
    public int deleteResultSasById(int[] id) {
        testResultSasDao.deleteSas(id);
        return testResultSasDao.deleteResultSasById(id);
    }

    @Override
    public List<TestResultSas> queryResultById(Integer id) {
        return testResultSasDao.queryResultById(id);
    }

    @Override
    public List<TestResultSasTotal> queryAllResultSas() {
        List<TestResultSasTotal> list = testResultSasDao.queryAllResultSas();
        return list;

    }

    @Override
    public List<TestResultSas> queryBySasTester(int id, String type) {
                return testResultSasDao.queryBySasTester(id);
    }

    @Override
    public Page<Map<String, Object>> getByTesterId(PageOrder pageOrder, Integer id) {
        //拿出pageOrder里面的所有数据
        PageHelper.startPage(pageOrder.getPage(), pageOrder.getLimit());
        //判断数据是否为空
        if (ObjectUtil.isNotEmpty(pageOrder.getField())) {
            PageHelper.orderBy(pageOrder.getFieldOrder());
        }
        return (Page<Map<String,Object>>) testResultSasDao.getByTesterId(id);
    }

    @Override
    public Page<ReturnRecords> getReturnRecords(PageOrder pageOrder, ReturnRecords records) {
        //拿出pageOrder里面的所有数据
        PageHelper.startPage(pageOrder.getPage(), pageOrder.getLimit());
        //判断数据是否为空
        if (ObjectUtil.isNotEmpty(pageOrder.getField())) {
            PageHelper.orderBy(pageOrder.getFieldOrder());
        }
        return (Page<ReturnRecords>) returnRecordsDao.getReturnRecordsSAS(records);
    }

    @Override
    public int insertReturn(ReturnRecords records) {
        return returnRecordsDao.insertSAS(records);
    }

    @Override
    public Integer deleteReturn(int[] id) {
        return returnRecordsDao.deleSas(id);
    }

    @Override
    public Integer updateReturn(ReturnRecords returnRecords) {
        return returnRecordsDao.updateSas(returnRecords);
    }

    @Override
    public List<Map<String, Object>> getPlanSASId() {
        return testResultSasDao.getPlanSASId();
    }
}
